//
//  XDMailMainViewController.m
//  iphone.mobileoa
//
//  Created by 李亚春 on 13-5-30.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "XDMailMainViewController.h"
#import "TDBadgedCell.h"
#import "User_GetInfo_Task.h"
#import "StringUtil.h"
#import "XDMailListViewController.h"
#import "XDMailSendViewController.h"

@interface XDMailMainViewController ()
{
    NSString *inboxallnums;
    NSString * wdmailnums;
    NSString * outmailnums;
    
    NSString *User_GetInfo_TaskGuid;
}
@end

@implementation XDMailMainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    inboxallnums = @"";
    wdmailnums = @"";
    outmailnums = @"";
    User_GetInfo_TaskGuid = [[[User_GetInfo_Task alloc]initWithContext:self andParams:self.getPassDictionary]startTask];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma 处理
-(void)refreshUIWithThreadGuid:(NSString *)threadGuid andData:(NSObject *)obj
{
    if ([User_GetInfo_TaskGuid isEqualToString:threadGuid]) {
        NSString *bs = [(NSString *)obj retain];
        inboxallnums = [[StringUtil getXMLFormatedAttribute:bs :@"MailReceiveCount"]retain];
        wdmailnums = [[StringUtil getXMLFormatedAttribute:bs :@"NewMailsCount"]retain];
        outmailnums = [[StringUtil getXMLFormatedAttribute:bs :@"MailSendCount"]retain];
        [self.tv reloadData];
    }
}

#pragma tableview

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    
    TDBadgedCell *cell = [[[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (indexPath.row==0) {
        cell.textLabel.text = [NSString stringWithFormat:@"收件箱"];
        if (wdmailnums.length>0||inboxallnums.length>0) {
            cell.badgeString = [NSString stringWithFormat:@"%@/%@",wdmailnums,inboxallnums];
        }
        
        cell.badgeColor = [UIColor colorWithRed:0.197 green:0.592 blue:0.219 alpha:1.000];
        cell.badge.radius = 9;
    }
    else if(indexPath.row==1)
    {
        cell.textLabel.text = [NSString stringWithFormat:@"发件箱"];
        if (outmailnums.length>0) {
            cell.badgeString = outmailnums;
        }
        
        cell.badge.radius = 9;
    }
    else if(indexPath.row==2)
    {
        cell.textLabel.text = [NSString stringWithFormat:@"写邮件"];
    }
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
        [params setObject:@"收件箱" forKey:@"viewtitle"];
        [params setObject:@"100000" forKey:@"boxType"];
        XDMailListViewController *vc = [[XDMailListViewController alloc]initWithParams:params];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if(indexPath.row==1)
    {
        NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
        [params setObject:@"发件箱" forKey:@"viewtitle"];
        [params setObject:@"100001" forKey:@"boxType"];
        XDMailListViewController *vc = [[XDMailListViewController alloc]initWithParams:params];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.row==2)
    {
        NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
        [params setObject:@"写邮件" forKey:@"viewtitle"];
        XDMailSendViewController *vc = [[XDMailSendViewController alloc]initWithParams:params];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}


- (void)dealloc {
    [_tv release];
    [super dealloc];
}
- (void)viewDidUnload {
    [self setTv:nil];
    [super viewDidUnload];
}
@end
